package com.ruoyi.web.controller.byManager;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.alibaba.fastjson.JSONObject;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain.BySubjectClassify;
import com.ruoyi.system.service.IBySubjectClassifyService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

@RestController
@RequestMapping("/by/bubjectClassify")
public class BySubjectClassifyController extends BaseController {
    @Autowired
    private IBySubjectClassifyService bySubjectClassifyService;

    @PostMapping("getAllSubjectNoTop")
    public AjaxResult getAllSubjectNoTop(@RequestBody String param){
        JSONObject json = JSONObject.parseObject(param);
        return AjaxResult.success(bySubjectClassifyService.getAllSubjectNoTopForById(json));
    }

    /**
     * 查询学科分类列表
     */
    @PreAuthorize("@ss.hasPermi('by:classify:list')")
    @GetMapping("/list")
    public AjaxResult list(BySubjectClassify bySubjectClassify)
    {
        /*startPage();
        List<BySubjectClassify> list = bySubjectClassifyService.selectBySubjectClassifyList(bySubjectClassify);
        return getDataTable(list);*/
        List<BySubjectClassify> list = bySubjectClassifyService.queryAllTable();
        return AjaxResult.success(list);
    }

    /**
     * 导出学科分类列表
     */
    @PreAuthorize("@ss.hasPermi('by:classify:export')")
    @Log(title = "学科分类", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, BySubjectClassify bySubjectClassify)
    {
        List<BySubjectClassify> list = bySubjectClassifyService.selectBySubjectClassifyList(bySubjectClassify);
        ExcelUtil<BySubjectClassify> util = new ExcelUtil<BySubjectClassify>(BySubjectClassify.class);
        util.exportExcel(response, list, "学科分类数据");
    }

    /**
     * 获取学科分类详细信息
     */
    @PreAuthorize("@ss.hasPermi('by:classify:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(bySubjectClassifyService.selectBySubjectClassifyById(id));
    }

    /**
     * 新增学科分类
     */
    @PreAuthorize("@ss.hasPermi('by:classify:add')")
    @Log(title = "学科分类", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody BySubjectClassify bySubjectClassify)
    {
        return toAjax(bySubjectClassifyService.insertBySubjectClassify(bySubjectClassify));
    }

    /**
     * 修改学科分类
     */
    @PreAuthorize("@ss.hasPermi('by:classify:edit')")
    @Log(title = "学科分类", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody BySubjectClassify bySubjectClassify)
    {
        return toAjax(bySubjectClassifyService.updateBySubjectClassify(bySubjectClassify));
    }

    /**
     * 删除学科分类
     */
    @PreAuthorize("@ss.hasPermi('by:classify:remove')")
    @Log(title = "学科分类", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(bySubjectClassifyService.deleteBySubjectClassifyByIds(ids));
    }
}
